package mysql

import "gorm.io/gorm"

type GoodsLx struct {
	gorm.Model
	GoodsTitle  string  `gorm:"type:varchar(50);index;not null;comment:商品标题;"`
	GoodsPrice  float32 `gorm:"type:decimal(10,2);default:0;comment:商品价格;"`
	GoodsStock  int64   `gorm:"type:int(10);index;default:0;comment:商品库存;"`
	GoodsStatus int8    `gorm:"type:tinyint(1);default:1; comment:1代表上架 0代表下架;"`
	GoodsCover  string  `gorm:"type:varchar(255);index;not null;comment:商品图片;"`
}

// 创建商品
func (g *GoodsLx) CreateGoods() error {
	return DB.Create(&g).Error
}

// 商品详情
func (g *GoodsLx) GoodsDetail(goodId int) error {
	return DB.Where("id = ?", goodId).First(&g).Error
}
